//写一个泛型类，找出数组当中的最大值，只要这个T，实现类这个接口就行
class Alg<T extends Comparable<T>>{
    public T findMaxVal(T[] array){
        T maxVal = array[0];
        for (int i = 1; i<array.length; i++){
            if(array[i].compareTo(maxVal)>0){
                maxVal = array[i];
            }
        }
        return maxVal;
    }

}
class Alg2{
    //静态方法
    public static<T extends Comparable<T>> T findMaxVal(T[] array){
        T maxVal = array[0];
        for (int i = 1; i<array.length; i++){
            if(array[i].compareTo(maxVal)>0){
                maxVal = array[i];
            }
        }
        return maxVal;
    }
}
class Alg3{
    //泛型方法:成员方法
    public <T extends Comparable<T>>T findMaxVal2(T[] array){
        T maxVal = array[0];
        for (int i = 1; i<array.length; i++){
            if(array[i].compareTo(maxVal)>0){
                maxVal = array[i];
            }
        }
        return maxVal;
    }
}
//静态的泛型方法
public class Test3 {
    public static void main(String[] args) {
        Alg3 alg3 = new Alg3();
        Integer[] array = {78,23,109,2,9,10};
        int val = alg3.findMaxVal2(array);
        System.out.println(val);
    }
    public static void main2(String[] args) {
        Integer[] array = {78,23,109,2,9,10};
        //int val = Alg2.<Integer>findMaxVal(array);
        //可以省略泛型类型
        int val = Alg2.findMaxVal(array);
        System.out.println(val);
    }

    public static void main1(String[] args) {
        Alg<Integer> alg = new  Alg<>();
        Integer[] array = {78,23,109,2,9,10};
        int val = alg.findMaxVal(array);
        System.out.println(val);
    }
}
